//
//  VarietyListCell.m
//  PigMarket
//
//  Created by mac on 2019/4/4.
//  Copyright © 2019 felix.pigmarket.oc. All rights reserved.
//

#import "VarietyListCell.h"

@interface VarietyListCell ()
/**
 图片
 */
@property (nonatomic , strong) UIImageView *pigImgView;
/**
 品种
 */
@property (nonatomic , strong) UILabel *varietyLab;
/**
 编号
 */
@property (nonatomic , strong) UILabel *pigNum;
/**
 出栏日期
 */
@property (nonatomic , strong) UILabel *dateLab;
/**
 价格
 */
@property (nonatomic , strong) YYLabel *priceLab;
/**
 体重
 */
@property (nonatomic , strong) UILabel *weightLab;
/**
 日龄
 */
@property (nonatomic , strong) UILabel *daysLab;
/**
 个性签名
 */
@property (nonatomic , strong) UILabel *personalRemarkLab;
/**
 price
 */
@property (nonatomic , strong) NSString *price;
@end
@implementation VarietyListCell

- (instancetype)initWithFrame:(CGRect)frame
{
    self = [super initWithFrame:frame];
    if (self) {
        [self initView];
        [self initLayout];
    }
    return self;
}

- (void)initView {
    // 添加子控件
    [self.contentView addSubview:self.pigImgView];
    [self.contentView addSubview:self.varietyLab];
    [self.contentView addSubview:self.pigNum];
    [self.contentView addSubview:self.daysLab];
    [self.contentView addSubview:self.weightLab];
    [self.contentView addSubview:self.dateLab];
    [self.contentView addSubview:self.priceLab];
    [self.contentView addSubview:self.personalRemarkLab];
}

- (void)initLayout {
    // 横向布局子控件
    [self.pigImgView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.mas_equalTo(15);
        make.left.mas_equalTo(15);
        make.size.mas_equalTo(CGSizeMake(90, 110));
        
    }];
    [self.varietyLab mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.mas_equalTo(15);
        make.left.mas_equalTo(self.pigImgView.mas_right).offset(12);
        make.width.mas_lessThanOrEqualTo(64 * [JTool getScreenWidthScale]);
        make.height.mas_equalTo(22);
    }];
    [self.pigNum mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerY.mas_equalTo(self.varietyLab.mas_centerY);
        make.left.mas_equalTo(self.varietyLab.mas_right).offset(10);
        make.height.mas_equalTo(18);
    }];
    [self.daysLab mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerY.mas_equalTo(self.varietyLab.mas_centerY);
        make.left.mas_equalTo(self.pigNum.mas_right).offset(5);
        make.height.mas_equalTo(18);
    }];
    [self.weightLab mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.mas_equalTo(self.varietyLab.mas_left);
        make.top.mas_equalTo(self.varietyLab.mas_bottom).offset(5);
        make.right.mas_equalTo(-15);
        make.height.mas_equalTo(18);
    }];
    [self.dateLab mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.mas_equalTo(self.varietyLab.mas_left);
        make.top.mas_equalTo(self.weightLab.mas_bottom).offset(5);
        make.right.mas_equalTo(-15);
        make.height.mas_equalTo(18);
    }];
    [self.priceLab mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.mas_equalTo(self.varietyLab.mas_left);
        make.top.mas_equalTo(self.dateLab.mas_bottom).offset(22);
        make.right.mas_equalTo(-15);
    }];
    [self.personalRemarkLab mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.mas_equalTo(15);
        make.top.mas_equalTo(self.pigImgView.mas_bottom).offset(15);
        make.right.mas_equalTo(-15);
        make.bottom.mas_equalTo(-15);
    }];
}

#pragma mark - getter and setter
- (void)setAdoptModel:(Adopt *)adoptModel {
    _adoptModel = adoptModel;
    [self.pigImgView sd_setImageWithURL:[NSURL URLWithString:adoptModel.materialUrl] placeholderImage:[UIImage imageNamed:@"placeholder_middle"]];
    self.varietyLab.text = adoptModel.varietiesName;
    self.pigNum.text = [NSString stringWithFormat:@"编号:%@",adoptModel.pigNum];
    self.daysLab.text = [NSString stringWithFormat:@"日龄%@日",adoptModel.age];
    self.dateLab.text = [NSString stringWithFormat:@"预出栏日期：%@（周期%@天）",adoptModel.expectOutDate,adoptModel.cycle];
    self.personalRemarkLab.text = adoptModel.personality;
    self.weightLab.text = [NSString stringWithFormat:@"体重：%.2fkg(%@)",adoptModel.weight,adoptModel.weighDate];
    self.price = [NSString stringWithFormat:@"首付价格：￥%@",adoptModel.payment];
    NSMutableAttributedString *text = [[NSMutableAttributedString alloc] initWithString:self.price];
    text.yy_font = [UIFont systemFontOfSize:17];
    text.yy_color = [UIColor colorWithHexString:@"#F25C62"];
    
    [text yy_setFont:[UIFont systemFontOfSize:12] range:NSMakeRange(0, 6)];
    [text yy_setColor:[UIColor colorWithHexString:@"#A1A1A1"] range:NSMakeRange(0, 5)];
    self.priceLab.attributedText = text;
}
- (UIImageView *)pigImgView {
    if (!_pigImgView) {
        _pigImgView = [[UIImageView alloc] init];
        _pigImgView.backgroundColor = [UIColor tipsGrayColor];
    }
    return _pigImgView;
}
- (UILabel *)varietyLab {
    if (!_varietyLab) {
        _varietyLab = [[UILabel alloc] init];
        _varietyLab.textColor = [UIColor textBlackColor];
        _varietyLab.font = [UIFont largerFont];
    }
    return _varietyLab;
}
- (UILabel *)pigNum {
    if (!_pigNum) {
        _pigNum = [[UILabel alloc] init];
        _pigNum.textColor = [UIColor colorWithHexString:@"#F1935F"];
        _pigNum.font = [UIFont systemFontOfSize:10];
        _pigNum.backgroundColor = [UIColor colorWithHexString:@"#FEF6EE"];
        _pigNum.layer.cornerRadius = 3;
        _pigNum.layer.masksToBounds = YES;
    }
    return _pigNum;
}
- (UILabel *)daysLab {
    if (!_daysLab) {
        _daysLab = [[UILabel alloc] init];
        _daysLab.backgroundColor = [UIColor colorWithHexString:@"#E9F9F0"];
        _daysLab.textColor = [UIColor primaryColor];
        _daysLab.font = [UIFont systemFontOfSize:10];
        _daysLab.layer.cornerRadius = 3;
        _daysLab.layer.masksToBounds = YES;
    }
    return _daysLab;
}
- (UILabel *)weightLab {
    if (!_weightLab) {
        _weightLab = [[UILabel alloc] init];
        _weightLab.textColor = [UIColor colorWithHexString:@"#666666"];
        _weightLab.font = [UIFont smallFont];
    }
    return _weightLab;
}
- (UILabel *)dateLab {
    if (!_dateLab) {
        _dateLab = [[UILabel alloc] init];
        _dateLab.textColor = [UIColor colorWithHexString:@"#666666"];
        _dateLab.font = [UIFont systemFontOfSize:13];
    }
    return _dateLab;
}
- (YYLabel *)priceLab {
    if (!_priceLab) {
        _priceLab = [[YYLabel alloc] init];
    }
    return _priceLab;
}
- (UILabel *)personalRemarkLab {
    if (!_personalRemarkLab) {
        _personalRemarkLab = [[UILabel alloc] init];
        _personalRemarkLab.textColor = [UIColor colorWithHexString:@"#606060"];
        _personalRemarkLab.font = [UIFont smallFont];
    }
    return _personalRemarkLab;
}

@end
